<%@page import="club.jeux.session.MessageBeanLocal"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="javax.jms.TextMessage"%>
<%@page import="javax.jms.MessageConsumer"%>
<%@page import="javax.jms.Session"%>
<%@page import="javax.jms.Connection"%>
<%@page import="javax.jms.Topic"%>
<%@page import="javax.jms.ConnectionFactory"%>
<%!
    Boolean firstTime;
%>
<%@include file="template/header.jsp" %>
<%@page import="club.jeux.session.Partie_PFC"%>
<%@page import="club.jeux.persistence.Joueur"%>
<%@page import="club.jeux.session.ServeurLocal"%>
<%@page import="club.jeux.session.Serveur"%>

<%@page import="javax.naming.InitialContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


        
    <%
    Joueur j = (Joueur) session.getAttribute("joueur");
    if(j == null){
        RequestDispatcher rd = request.getRequestDispatcher("connexion.jsp");
        rd.forward(request, response);
    }
    %>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <script language="Javascript">
          function timeout_trigger() {
               window.location = "salle.jsp";
           }

           function timeout_init() {
               setTimeout('timeout_trigger()',3000);
           }
           window.onload = timeout_init;
       </script>
        <title>Salle</title>
        <link rel="stylesheet" href="template/mediagroove.css" media="all">
    </head>
    <body>
        <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-0" style="width: 20%" >
        <h4>CHIFOUMI</h4>
        <p style="text-align: center;margin:0"><a href="jeu.jsp"><img width="133" height="119" alt="" class="art-lightbox" src="template/images/m_144.jpg"></a><br></p>
        <p style="margin: 0px; margin-bottom: 20px;text-align: center;">Jeu du pierre-feuille-ciseaux</p>

    </div><div class="art-layout-cell layout-item-0" style="width: 20%" >
        <h4>MORPION</h4>
        <p style="text-align: center;margin:0"><img width="102" height="102" alt="" src="template/images/Travel-Bus-128-2.png" class=""></p>
        <p style="margin: 0px; margin-bottom: 20px;text-align: center;">A venir...</p>
    </div><div class="art-layout-cell layout-item-0" style="width: 20%" >
        <h4>ECHECS</h4>
        <p style="text-align: center;margin:0"><img width="102" height="102" alt="" src="template/images/Mini-Plane-128-2.png"></p>
        <p style="margin: 0px; margin-bottom: 20px;text-align: center;">A venir...</p>
    </div><div class="art-layout-cell layout-item-0" style="width: 20%" >
        <h4>PUISSANCE 4</h4>
        <p style="text-align: center;margin:0"><img width="102" height="102" alt="" src="template/images/Mini-Cooper-128-2.png" class=""></p>
        <p style="margin: 0px; margin-bottom: 20px;text-align: center;">A venir...</p>
    </div><div class="art-layout-cell layout-item-0" style="width: 20%" >
        <h4>BATAILLE NAVALE</h4>
        <p style="text-align: center;margin:0"><img width="102" height="102" alt="" src="template/images/Sailingship-128-2.png" class=""></p>
        <p style="margin: 0px; margin-bottom: 20px;text-align: center;">A venir...</p>
    </div>
    </div>
    <center>
        <p class="titre">Bienvenue dans la salle de jeu !</p>
        <br/><br/>
        </center>
    <h3>Voici la liste des joueurs connectés :</h3>
    <table>
        <thead><tr>
                <th scope="col">Joueur</th>
                <th scope="col">Ratio</th>
            </tr></thead>
         <tbody>
   
        <%
          ServeurLocal salle=null;
        try {
            DecimalFormat df = (DecimalFormat)DecimalFormat.getNumberInstance();
            df.applyPattern("0.00" );
            InitialContext ic = new InitialContext();
            Object o = ic.lookup("java:comp/env/ServeurLocal");
            salle = (ServeurLocal) o;
            for (Joueur j2 : salle.getJoueur()){
                %>
                    <tr>
                    <th scope="row"><%=j2.getLogin()%></th>
                    <th scope="row"><%=df.format(j2.ratio())%></th>
                    </tr>
            <%
            }
       
        if(session.getAttribute("FTDisplay") == null){
            firstTime = true;
            session.setAttribute("FTDisplay", firstTime);
        }
        else{
              firstTime = (Boolean)session.getAttribute("FTDisplay");
        }
         
         
         
          }
        catch(Exception e){
            e.printStackTrace();
            out.println("probleme : " + e.toString()); 
        }
        %>
    </tbody>     
    </table>
         <center>
        <br/><br/>
        <input class="art-button" type="button" value="Deconnexion" onclick=" self.location.href='deconnexion.jsp'"/>


    <%
    if(firstTime){
             firstTime=false;
             session.setAttribute("FTDisplay", firstTime);
         }
    else{
        MessageBeanLocal messageBean = null;
        InitialContext ic = new InitialContext();
        Object o = ic.lookup("java:comp/env/MessageBeanLocal");
        messageBean = (MessageBeanLocal) o;
        String message = messageBean.receiveMessage();
        %>
        <h3><%=message%></h3>
        <%
        firstTime=true;
        session.setAttribute("FTDisplay", firstTime);
    }
          %>
          
    </center>        
<%@include file="template/footer.jsp" %>